package com.fast.alden.admin.web.controller.system;

import com.fast.alden.admin.annotation.OperationLog;
import com.fast.alden.admin.service.SysDepartmentService;
import com.fast.alden.data.model.SysDepartment;
import com.fast.alden.data.model.SysOperationType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Nullable;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门管理控制器
 */
@Tag(name = "SysDepartmentController", description = "部门管理")
@RestController
@RequestMapping("/department")
public class SysDepartmentController {
    @Resource
    private SysDepartmentService departmentService;

    @Operation(summary = "列表查询", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @PostMapping("/list")
    public List<SysDepartment> list(@RequestBody @Nullable SysDepartment searchVo) {
        return departmentService.search(searchVo);
    }

    @Operation(summary = "树表查询", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @PostMapping("/tree-list")
    public List<SysDepartment> treeList() {
        return departmentService.tree();
    }

    @Operation(summary = "根据ID查询", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @GetMapping("/retrieve/{id}")
    public SysDepartment retrieve(@PathVariable("id") Long id) {
        return departmentService.retrieve(id);
    }

    @OperationLog(title = "部门管理", type = SysOperationType.CREATE)
    @Operation(summary = "创建部门", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @PostMapping("/create")
    public Long create(@RequestBody SysDepartment department) {
        return departmentService.create(department).getId();
    }

    @OperationLog(title = "部门管理", type = SysOperationType.UPDATE)
    @Operation(summary = "修改部门", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @PutMapping("/update")
    public void update(@RequestBody SysDepartment department) {
        departmentService.update(department);
    }

    @OperationLog(title = "部门管理", type = SysOperationType.DELETE)
    @Operation(summary = "删除部门", security = @SecurityRequirement(name = "openApiSecurityScheme"))
    @DeleteMapping("/remove")
    public void remove(@RequestParam(name = "ids") List<Long> ids) {
        departmentService.remove(ids);
    }
}
